<?php
/**
 * Delete Action deletes a file from its fid (database)
 *   $_REQUEST['fid'] || $_REQUEST['sid']
 */
class FileListAction extends CAction {

    public function run() {
        $files    = array();
        $entity   = $_REQUEST['entity'];
        $EXid     = $_REQUEST['EXid'];
        Yii::trace("FilePanelAction $entity $EXid");

        // Temporal files in session
        $tempFiles = array();
        $sessionFiles = Yii::app()->session['temp_files'];
        if (isset($sessionFiles))
            foreach($sessionFiles as $f) $tempFiles[] = File::buildFromArray($f);

        if (isset($entity) && isset($EXid)) {
            $files = File::model()->findAll('entity=:entity AND EXid=:EXid', array(
                    ':entity'=>$entity,
                    ':EXid'=>$EXid));
        }
        $files = array_merge($files, $tempFiles);

        $this->getController()->renderPartial('ext.upload.plupload.views.draggableFileList',
                array('files'=>$files));
        exit(0); // To avoid loggers append things to request
    }
}
